package zuoye3;

import org.w3c.dom.ls.LSOutput;

import java.util.HashMap;

/**
 * 准备一个 HashMap 集合，统计字符串"123,456,789,123,456"中每个数字字符串出现的次数并打印出来。
 */
public class HashMapWork {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        String str = "123,456,789,123,456";
        String[] strArr = str.split(",");
        Integer number123 = 0;
        Integer number456 = 0;
        Integer number789 = 0;
        for (int i=0;i<strArr.length;i++) {
            if ("123".equals(strArr[i])){
                number123++;
            }
            if ("456".equals(strArr[i])){
                number456++;
            }
            if ("789".equals(strArr[i])){
                number789++;
            }
        }
        map.put("123",number123);
        map.put("456",number456);
        map.put("789",number789);
        System.out.println("字符串123出现的次数" + map.get("123"));
        System.out.println("字符串456出现的次数" + map.get("456"));
        System.out.println("字符串789出现的次数" + map.get("789"));
    }

}

